package com.simp.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author pan.shun
 * @version 2.0
 * @since 2022/3/24 21:33
 */
@Data
@Component
@ConfigurationProperties(prefix = "spring.datasource")
public class DbConfig {

    /**
     * 驱动
     */
    private String driverClassName;

    /**
     * 数据库名
     */
    private String dbName;

    /**
     * 数据源类型
     */
    private String type;

    /**
     * 连接url
     */
    private String url;

    /**
     * 用户名
     */
    private String userName;

    /**
     * 密码
     */
    private String password;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DbConfig dbConfig = (DbConfig) o;
        return Objects.equals(driverClassName, dbConfig.driverClassName) && Objects.equals(dbName, dbConfig.dbName) && Objects.equals(type, dbConfig.type) && Objects.equals(url, dbConfig.url) && Objects.equals(userName, dbConfig.userName) && Objects.equals(password, dbConfig.password);
    }

    @Override
    public int hashCode() {
        return Objects.hash(driverClassName, dbName, type, url, userName, password);
    }

    @Override
    public String toString() {
        return "{" +
                "driverClassName='" + driverClassName + '\'' +
                ", dbName='" + dbName + '\'' +
                ", type='" + type + '\'' +
                ", url='" + url + '\'' +
                ", userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
